<?php
/**
 * DataObjectAttachment
 *
 * DataObjectAttachment is a little class used to save Dataobject attachments 
 * @author King Beto <apardo@adverit.com>
 * @version 1.0
 * @package database
 * @update 2/18/2008 6:25:53 PM
 */
require_once(dirname(__FILE__) ."/Error.php");

/**
 * DataObjectAttachment is a little class used to save Dataobject attachments 
 * @package database
 */
class DataObjectAttachment extends File
{
    /**
     * The DataObject object.
     * @access private
     * @var _dataobject
     */
    public $_dataobject;
    
    public function __construct($dataObject)
    {
        $this->_dataObject = $dataObject;
        $this->dirPath = DIR_FILE_UPLOAD ."/". $this->_dataObject->_dbTable;
        $this->urlPath = $GLOBALS["CONF"]["url"]["dir_file_upload"] ."/". $this->_dataObject->_dbTable;
    }

    public function save($arFile, $prefix_name='', $name='', $overwrite = true)
    {
        $this->filename = $prefix_name ."_". ($name)? $name : $this->postFilename;
        if ($this->catchPost($arFile) == UPLOAD_ERR_OK)
        {
            if ($this->savePost())
            {
                if ($overwrite) @unlink($this->dirPath ."/". $this->filename);
                return 1;
            }
        }
        return 0;
    }
}

?>
